package com.pym.common;

import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class PaginationUtils {

    private Integer indexNo;
    /**
     * 每页显示行数
     * */
    private int rows = 10;

    private List<?> list;

    public Integer getIndexNo() {
        return indexNo;
    }

    public void setIndexNo(Integer indexNo) {
        if(indexNo == null || indexNo == 0){
            indexNo = 1;
        }
        this.indexNo = indexNo;
    }

    public List<?> getList() {
        int size = list.size();
        int head = (indexNo-1)*rows;
        int tail = indexNo*rows;
        if(head>size){
            head = size;
        }
        if(tail >size){
            tail = size;
        }
        return list.subList(head,tail);
    }


    public void setList(List<?> list) {
        this.list = list;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }
}


